# eric7.MicroPython.MicroPythonWidget

Module implementing the MicroPython REPL widget.

### Global Attributes

HasQtChartsOrGraphs
HasQtSerialport

### Classes

MicroPythonWidget | Class implementing the MicroPython REPL widget.

### Functions

None

## MicroPythonWidget

Class implementing the MicroPython REPL widget.

### Signals

aboutToDisconnect()
  emitted to indicate the imminent disconnect from the currently device
dataReceived(data)
  emitted to send data received via the serial connection for further processing
disconnected()
  emitted after the device was disconnected

### Derived from

QWidget, Ui_MicroPythonWidget

### Class Attributes

DeviceBoardRole
DeviceInterfaceTypeRole
DevicePidRole
DevicePortRole
DeviceSerNoRole
DeviceTypeRole
DeviceVidRole
DeviceWebreplUrlRole
ManualMarker

### Class Methods

None

### Methods

MicroPythonWidget | Constructor
__aboutToShowSuperMenu | Private slot to populate the Super Menu before showing it.
__addUnknownDevices | Private method to add devices to the list of manually added boards.
__compileEditor2Mpy | Private slot to cross compile the current editor to a .mpy file.
__compileFile2Mpy | Private slot to cross compile a Python file (*.py) to a .mpy file.
__configure | Private slot to open the MicroPython configuration page.
__configureWebreplUrls | Private slot to configure the list of selectable WebREPL URLs.
__connectToDevice | Private method to connect to the selected device.
__convertToUF2 | Private slot to convert a non-UF2 MicroPython firmware file to UF2.
__crossCompile | Private method to cross compile a Python file to a .mpy file.
__disconnectFromDevice | Private method to disconnect from the device.
__downloadFirmware | Private slot to open the firmware download page.
__downloadFromUrl | Private method to open a web browser for the given URL.
__flashUF2 | Private slot to flash MicroPython/CircuitPython to a device support the UF2 bootloader.
__getDeviceTime | Private method to get a string containing the date and time of the connected device.
__handlePreferencesChanged | Private slot to handle a change in preferences.
__installPackage | Private slot to install packages using the given method.
__manageIgnored | Private slot to manage the list of ignored serial devices.
__manageUnknownDevices | Private slot to manage manually added boards (i.e.
__mpyCrossAvailable | Private method to check the availability of mpy-cross.
__populateDeviceTypeComboBox | Private method to populate the device type selector.
__quit | Private slot to quit the main (MicroPython) window.
__setConnected | Private method to set the connection status LED.
__showBoardInformation | Private slot to show all available information about a board.
__showBuiltinModules | Private slot to show a list of builtin modules.
__showDeviceTime | Private slot to show the date and time of the connected device.
__showDeviceVersion | Private slot to show some version info about MicroPython of the device.
__showDocumentation | Private slot to open the documentation URL for the selected device.
__showImplementation | Private slot to show some implementation related information.
__showLocalAndDeviceTime | Private slot to show the local and device time side-by-side.
__showLocalTime | Private slot to show the local date and time.
__showNoDeviceMessage | Private method to show a message dialog indicating a missing device.
__shutdown | Private method to perform some shutdown actions.
__synchronizeTime | Private slot to set the time of the connected device to the local computer's time.
deviceInterface | Public method to get a reference to the device interface object.
deviceSupportsLocalFileAccess | Public method to indicate that the device access the device file system via a local directory.
getCurrentPort | Public method to determine the port path of the selected device.
getDevice | Public method to get a reference to the current device.
getDeviceWorkspace | Public method to get the workspace directory of the device.
getFileManager | Public method to get a reference to the file manager interface.
handleDataFlood | Public slot handling a data flood from the device.
insertData | Public method to insert some data as if it was sent directly from the device.
isConnected | Public method to get the MicroPython device connection state.
isLinkConnected | Public method to get the link connection state.
isMicrobit | Public method to check, if the connected/selected device is a BBC micro:bit or Calliope mini.
on_chartButton_clicked | Private slot to open a chart view to plot data received from the connected device.
on_connectButton_clicked | Private slot to connect to the selected device or disconnect from the currently connected device.
on_deviceTypeComboBox_activated | Private slot handling the selection of a device type.
on_filesButton_clicked | Private slot to open a file manager window to the connected device.
on_replButton_clicked | Private slot to connect to enable or disable the REPL widget.
on_runButton_clicked | Private slot to execute the script of the active editor on the selected device.
on_stopButton_clicked | Private slot to stop the currently executed script.
setActionButtons | Public method to set the enabled state of the various action buttons.
showError | Public method to show some error message.

### Static Methods

None

#### MicroPythonWidget (Constructor)

MicroPythonWidget(parent=None, forMPyWindow=False)

Constructor

parent (QWidget (optional))
  reference to the parent widget (defaults to None)
forMPyWindow (bool (optional))
  flag indicating the MicroPythonWindow variant (defaults to False)

#### MicroPythonWidget.__aboutToShowSuperMenu

__aboutToShowSuperMenu()

Private slot to populate the Super Menu before showing it.

#### MicroPythonWidget.__addUnknownDevices

__addUnknownDevices(devices)

Private method to add devices to the list of manually added boards.

devices (list of tuple of (int, int, str))
  list of not ignored but unknown devices

#### MicroPythonWidget.__compileEditor2Mpy

__compileEditor2Mpy()

Private slot to cross compile the current editor to a .mpy file.

#### MicroPythonWidget.__compileFile2Mpy

__compileFile2Mpy()

Private slot to cross compile a Python file (*.py) to a .mpy file.

#### MicroPythonWidget.__configure

__configure()

Private slot to open the MicroPython configuration page.

#### MicroPythonWidget.__configureWebreplUrls

__configureWebreplUrls()

Private slot to configure the list of selectable WebREPL URLs.

#### MicroPythonWidget.__connectToDevice

__connectToDevice(withAutostart=False)

Private method to connect to the selected device.

withAutostart (bool)
  flag indicating to start the repl and file manager automatically

Raises ValueError:
  raised to indicate an unsupported interface type

#### MicroPythonWidget.__convertToUF2

__convertToUF2()

Private slot to convert a non-UF2 MicroPython firmware file to UF2.

#### MicroPythonWidget.__crossCompile

__crossCompile(pythonFile="", title="")

Private method to cross compile a Python file to a .mpy file.

pythonFile (str)
  name of the Python file to be compiled
title (str)
  title for the various dialogs

#### MicroPythonWidget.__disconnectFromDevice

__disconnectFromDevice()

Private method to disconnect from the device.

#### MicroPythonWidget.__downloadFirmware

__downloadFirmware()

Private slot to open the firmware download page.

#### MicroPythonWidget.__downloadFromUrl

__downloadFromUrl(url)

Private method to open a web browser for the given URL.

url (str)
  URL to be opened

#### MicroPythonWidget.__flashUF2

__flashUF2()

Private slot to flash MicroPython/CircuitPython to a device support the UF2 bootloader.

#### MicroPythonWidget.__getDeviceTime

__getDeviceTime()

Private method to get a string containing the date and time of the connected device.

Return:
  date and time of the connected device

Return Type:
  str

#### MicroPythonWidget.__handlePreferencesChanged

__handlePreferencesChanged()

Private slot to handle a change in preferences.

#### MicroPythonWidget.__installPackage

__installPackage(method)

Private slot to install packages using the given method.

method (str)
  package management method to be used (one of 'upip' or 'mip')

Raises ValueError:
  raised to indicate an unsupported package management method

#### MicroPythonWidget.__manageIgnored

__manageIgnored()

Private slot to manage the list of ignored serial devices.

#### MicroPythonWidget.__manageUnknownDevices

__manageUnknownDevices()

Private slot to manage manually added boards (i.e. those not in the list of supported boards).

#### MicroPythonWidget.__mpyCrossAvailable

__mpyCrossAvailable()

Private method to check the availability of mpy-cross.

Return:
  flag indicating the availability of mpy-cross

Return Type:
  bool

#### MicroPythonWidget.__populateDeviceTypeComboBox

__populateDeviceTypeComboBox()

Private method to populate the device type selector.

#### MicroPythonWidget.__quit

__quit()

Private slot to quit the main (MicroPython) window.

#### MicroPythonWidget.__setConnected

__setConnected(connected)

Private method to set the connection status LED.

connected (bool)
  connection state

#### MicroPythonWidget.__showBoardInformation

__showBoardInformation()

Private slot to show all available information about a board.

#### MicroPythonWidget.__showBuiltinModules

__showBuiltinModules()

Private slot to show a list of builtin modules.

#### MicroPythonWidget.__showDeviceTime

__showDeviceTime()

Private slot to show the date and time of the connected device.

#### MicroPythonWidget.__showDeviceVersion

__showDeviceVersion()

Private slot to show some version info about MicroPython of the device.

#### MicroPythonWidget.__showDocumentation

__showDocumentation()

Private slot to open the documentation URL for the selected device.

#### MicroPythonWidget.__showImplementation

__showImplementation()

Private slot to show some implementation related information.

#### MicroPythonWidget.__showLocalAndDeviceTime

__showLocalAndDeviceTime()

Private slot to show the local and device time side-by-side.

#### MicroPythonWidget.__showLocalTime

__showLocalTime()

Private slot to show the local date and time.

#### MicroPythonWidget.__showNoDeviceMessage

__showNoDeviceMessage()

Private method to show a message dialog indicating a missing device.

#### MicroPythonWidget.__shutdown

__shutdown()

Private method to perform some shutdown actions.

#### MicroPythonWidget.__synchronizeTime

__synchronizeTime(quiet=False)

Private slot to set the time of the connected device to the local computer's time.

quiet (bool)
  flag indicating to not show a message

#### MicroPythonWidget.deviceInterface

deviceInterface()

Public method to get a reference to the device interface object.

Return:
  reference to the commands interface object

Return Type:
  MicroPythonDeviceInterface

#### MicroPythonWidget.deviceSupportsLocalFileAccess

deviceSupportsLocalFileAccess()

Public method to indicate that the device access the device file system via a local directory.

Return:
  flag indicating file access via local directory

Return Type:
  bool

#### MicroPythonWidget.getCurrentPort

getCurrentPort()

Public method to determine the port path of the selected device.

Return:
  path of the port of the selected device

Return Type:
  str

#### MicroPythonWidget.getDevice

getDevice()

Public method to get a reference to the current device.

Return:
  reference to the current device

Return Type:
  BaseDevice

#### MicroPythonWidget.getDeviceWorkspace

getDeviceWorkspace()

Public method to get the workspace directory of the device.

Return:
  workspace directory of the device

Return Type:
  str

#### MicroPythonWidget.getFileManager

getFileManager()

Public method to get a reference to the file manager interface.

Return:
  reference to the file manager interface

Return Type:
  MicroPythonFileManager

#### MicroPythonWidget.handleDataFlood

handleDataFlood()

Public slot handling a data flood from the device.

#### MicroPythonWidget.insertData

insertData(data)

Public method to insert some data as if it was sent directly from the device.

data (str or bytes)
  data to be inserted into the REPL pane

#### MicroPythonWidget.isConnected

isConnected()

Public method to get the MicroPython device connection state.

Return:
  connection state

Return Type:
  bool

#### MicroPythonWidget.isLinkConnected

isLinkConnected()

Public method to get the link connection state.

Return:
  connection state

Return Type:
  bool

#### MicroPythonWidget.isMicrobit

isMicrobit()

Public method to check, if the connected/selected device is a BBC micro:bit or Calliope mini.

Return:
  flag indicating a micro:bit device

Return Type:
  bool

#### MicroPythonWidget.on_chartButton_clicked

on_chartButton_clicked(checked)

Private slot to open a chart view to plot data received from the connected device.

If the selected device is not connected yet, this will be done now.

checked (bool)
  state of the button

Return:
  flag indicating a successful connect or disconnect

Return Type:
  bool

#### MicroPythonWidget.on_connectButton_clicked

on_connectButton_clicked()

Private slot to connect to the selected device or disconnect from the currently connected device.

#### MicroPythonWidget.on_deviceTypeComboBox_activated

on_deviceTypeComboBox_activated(index)

Private slot handling the selection of a device type.

index (int)
  index of the selected device

#### MicroPythonWidget.on_filesButton_clicked

on_filesButton_clicked(checked)

Private slot to open a file manager window to the connected device.

If the selected device is not connected yet, this will be done now.

checked (bool)
  state of the button

#### MicroPythonWidget.on_replButton_clicked

on_replButton_clicked(checked)

Private slot to connect to enable or disable the REPL widget.

If the selected device is not connected yet, this will be done now.

checked (bool)
  state of the button

#### MicroPythonWidget.on_runButton_clicked

on_runButton_clicked()

Private slot to execute the script of the active editor on the selected device.

If the REPL is not active yet, it will be activated, which might cause an unconnected device to be connected.

#### MicroPythonWidget.on_stopButton_clicked

on_stopButton_clicked()

Private slot to stop the currently executed script.

#### MicroPythonWidget.setActionButtons

setActionButtons(**kwargs)

Public method to set the enabled state of the various action buttons.

kwargs= (dict)
  keyword arguments containg the enabled states (keys are 'run', 'repl', 'files', 'chart', 'open', 'save')

#### MicroPythonWidget.showError

showError(method, error)

Public method to show some error message.

method (str)
  name of the method the error occured in
error (str)
  error message

Up